<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>分支机构管理</el-breadcrumb-item>
      <el-breadcrumb-item>新增分支机构</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>

    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="80px"
      style="width: 350px"
    >
      <el-form-item label="公司名称" prop="title">
        <el-input v-model="form.title"></el-input>
      </el-form-item>
      <el-form-item label="公司地址" prop="address">
        <el-input v-model="form.address"></el-input>
      </el-form-item>
      <el-form-item label="邮编" prop="postal_code">
        <el-input v-model="form.postal_code"></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="传真" prop="fax">
        <el-input v-model="form.fax"></el-input>
      </el-form-item>
      <el-form-item label="网址" prop="website">
        <el-input v-model="form.website"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">新增公司</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import httpApi from '@/http';
export default {
  data() {
    return {
      form: {
        name: "",
        address: "",
        youbian: "",
        phone: "",
        number: "",
        website: "",
      },
      rules: {
        title: [{ required: true, message: "公司名为必填项", trigger: "blur" }],
        address: [{ required: true, message: "地址为必填项", trigger: "blur" }],
        postal_code: [{ required: true, message: "邮编为必填项", trigger: "blur" }],
        phone: [{ required: true, message: "电话为必填项", trigger: "blur" }],
        fax: [{ required: true, message: "传真为必填项", trigger: "blur" }],
        website: [{ required: true, message: "网址为必填项", trigger: "blur" }],
      },
    };
  },
  methods: {
    onSubmit() {
      
      console.log(this.form);
      // 验证表单是否符合rules的要求
      this.$refs["form"].validate((valid) => {
        if (valid) {
          httpApi.movieApi.add(this.form).then(res=>{
            if (res.data.code == 200) {
              // 跳转到列表
              this.$message.success("恭喜，添加成功");
              this.$router.push("/home/movie-list");
            }
          })
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>